import $utils from "@/utils/utils";
export default {
  namespaced: true,
  state: {
    token: $utils.localStorage.getItem("token") || "",
    userInfo: $utils.localStorage.getItem("userInfo") || {},
  },
  getters: {},
  mutations: {
    SET_TOKEN: (state, data) => {
      state.token = data;
      $utils.localStorage.setItem("token", data);
    },
    SET_USER_INFO: (state, data) => {
      state.userInfo = data;
      $utils.localStorage.setItem("userInfo", data);
    },
  },
  actions: {
    setToken({ commit }, data) {
      commit("SET_TOKEN", data);
    },
    setUserInfo({ commit }, data) {
      commit("SET_USER_INFO", data);
    },
    logout({ commit, dispatch }) {
      commit("SET_TOKEN", "");
      commit("SET_USER_INFO", {});
      dispatch("setting/logout", {}, { root: true });
      dispatch("permission/logout", {}, { root: true });
      return Promise.resolve();
    },
  },
};
